<!--************************************************************************************************-->
<!-- < Group.php >                                                                               -->
<!-- Copyright (c) 2012-2013 San Yat-sun University School of Software                              -->
<!-- Modifier: Xiaoxin Mo                                                                 -->
<!-- Stu : 10389159                                                                                 -->
<!-- Date: 2012-12-23                                                                               -->
<!-- Destription : 增加变量GroupBrief，增加findNGroups($N)(返回前N个Group)，findGrouplistByMaID, findGroupnamesByMaID                                                            -->
<!--                                                                                                -->
<!-- Version : 2.0                                                                                  -->
<!--************************************************************************************************-->

<?php
	include_once("../persistent/BaseObject.php");
	
	class Group extends BaseObject
	{
		public $Groupname;
		public $ManagerName;
		// added by xiaoxin
		public $GroupBrief;
		
		public function __construct($d)
		{
			$this->tableName = "Groups";
			parent::__construct($d);	
		}
		
		//=========================added by xiaoxin===============================
		public function findValueByGroupname($Groupname){
			$con = $this->openDB();
			
			// 找出Username的条目
			$sql = "SELECT * FROM $this->tableName
			WHERE Groupname = '$Groupname'";
			
			return mysql_fetch_array($this->startSQL($sql,$con));
		}
		
		public function findNGroups($N)
		{
			$con = $this->openDB();
			
			$sql = "SELECT * FROM $this->tableName
			LIMIT $N";
			
			return $this->startSQL($sql,$con);
		}
		
		// find groups created by current user
		public function findGrouplistByMaName($maName){
			$con = $this->openDB();
			
			$sql = "SELECT * FROM $this->tableName
			WHERE ManagerName = '$maName'";
			
			return $this->startSQL($sql,$con);
		}
		
		public function findNGroupsByMaName($maName, $N){
			$con = $this->openDB();
			
			$sql = "SELECT * FROM $this->tableName
			WHERE ManagerName = '$maName'
			LIMIT $N";
			
			return $this->startSQL($sql,$con);
		}
		
		public function findGroupnamesByMaName($maName, $N){
			if ($N == null)
				$group_list = $this->findGrouplistByMaName($maName);
			else
				$group_list = $this->findNGroupsByMaName($maName, $N);
				
			$group_names = array();
			
			while ($group = mysql_fetch_array($group_list))
				$group_names[] = $group['Groupname'];
			
			return $group_names;
		}
	}

?>
